package cn.aihongbo.mysql.data

import java.sql.DriverManager
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine

object DBHelper {

    val url = "jdbc:mysql://localhost:3306/kmp_db"
    val user = "root"
    val password = "zhaohongbo"

    suspend fun queryUname(): String = suspendCoroutine { continuation ->
        val connection by lazy { DriverManager.getConnection(url, user, password) }
        connection.use { conn ->
            val statement = conn.createStatement()
            val resultSet = statement.executeQuery("SELECT * FROM kmp_db_user")
            while (resultSet.next()) {
                val uname = resultSet.getString("uname")
                val pwd = resultSet.getString("pwd")
                val create_date = resultSet.getString("create_date")
                continuation.resume("${uname}的密码是:${pwd}，账号创建于${create_date}")
            }
        }
    }
}